/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qlvbdq.model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import qlvbdq.jdbc.SQLServerConnect;
import qlvbdq.objects.ObThoGiaCong;

/**
 *
 * @author tuan
 */
public class MThoGiaCong {
    SQLServerConnect connect;

    public MThoGiaCong() {
    }
    
    //if get ThoGiaCong by MaTho then thogc.Ten = null and diachi = null
    public ArrayList<ObThoGiaCong> GetThoGiaCongByRule(ObThoGiaCong thogc) throws SQLException {
        ArrayList<ObThoGiaCong> listTho = new ArrayList<ObThoGiaCong>();
        Object[] objs = { thogc.getMaTho(), thogc.getTenTho(), thogc.getDiaChi() };
        ResultSet result;
        result = connect.getDataFromStore("GetThoGiaCongByRuleFromDatabase(?, ?, ?)", objs);
        ObThoGiaCong ThoGiaCong = null;
        while (result.next()) {
            ThoGiaCong = new ObThoGiaCong(result.getString("MATHO"), 
                        result.getString("TENTHO"), result.getString("DIACHI"));
            listTho.add(ThoGiaCong);
        }
        return listTho;
    }
    
    public int UpdateThoGiaCong( ObThoGiaCong thogc ) {
        Object[] objs = { thogc.getMaTho(), thogc.getTenTho(), thogc.getDiaChi() };
        return connect.updateDataToDatabase("UpdateThoGiaCongFromDatabase(?, ?, ?)", objs);
    }
    
    public int DeleteThoGiaCong( ObThoGiaCong thogc ) {
        Object[] objs = { thogc.getMaTho() };
        return connect.updateDataToDatabase("UpdateThoGiaCongToDatabase(?)", objs);
    }
    
    public int InsertThoGiaCong( ObThoGiaCong thogc ) {
        Object[] objs = { thogc.getMaTho(), thogc.getTenTho(), thogc.getDiaChi() };
        return connect.updateDataToDatabase("InsertThoGiaCongFromDatabase(?, ?, ?)", objs);
    }
}
